﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;


namespace AppServer.Controllers.System
{
    [Route("api/[controller]")]
    [ApiController]
    public class System2Controller : SysControllerBase
    { 
        //部门
        // POST: api/System1
        [HttpPost]
        public ActionResult<string> Post([FromBody] dynamic data)
        {
            string jsTimeStamp = data.jsTimeStamp;
            string Action = data.Action == null ? "Get" : data.Action;
            string rtstr = "";
            //得到列表
            if (Action == "Get")
            {
                rtstr = Get(data);
            }
            if (Action == "Save")
            {
                rtstr = Save(data);
            }
            return rtstr;
        }

        /// <summary>
        /// 得到用户列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Get(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            string search = postdata["search"].ToString();
            BLLsystem_2 bll = new BLLsystem_2();
            List<Mssystem_2> mssys2 = new List<Mssystem_2>();
            MsQuery msq = new MsQuery();
            if (!string.IsNullOrEmpty(search))
            {
                msq.strquery += " and (system_2.System_2_20 like '%" + search + "%' ";
                msq.strquery += " or system_2.System_2_30 like '%" + search + "%' ";
                msq.strquery += " or system_2.System_2_110 like '%" + search + "%' ";
                msq.strquery += " )";
            }
            mssys2 = bll.Getsystem_2MsByQuery(msq);
            return JArray.FromObject(mssys2).ToString();
        }


        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Save(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            string sys2data = postdata["data"].ToString();
            Mssystem_2 ms = Mssystem_2.parse(sys2data);
            string res = "";
            MsReturned msr = new MsReturned();
            msr = new BLLsystem_2().Savesystem_2(ms);
            res = JObject.FromObject(msr).ToString();
            return res;
        }
    }
}